import os
import time
import itertools

depths = [6]
l2_leaf_regs = [3]

epochs = [1000]

model = 'catboost'  #

runed_id = 5
runing_id = []
max_run_num = 1
running_num = 0

for grid in itertools.product(depths, epochs, l2_leaf_regs):
    depth, epoch, l2_leaf_reg = grid
    if running_num == max_run_num:
        while True:
            for run_id in runing_id:
                time.sleep(15)
                # logging.info('scanning %d.log......\n',run_id)
                for line in open(str(run_id) + '_' + model + '_submit.log'):
                    if '完成训练' in line:
                        running_num -= 1
                        runing_id.remove(run_id)

            if running_num != max_run_num:
                break

    os.system(' nohup python3.6 -u wm_catboost.py --depth ' + str(depth) + ' \
    --epoch ' + str(epoch) + ' \
    --l2_leaf_reg ' + str(l2_leaf_reg) + ' \
    --run_id ' + str(runed_id) + ' >' + str(runed_id) + '_' + model + '_submit.log 2>&1 &')
    runing_id.append(runed_id)
    runed_id += 1
    running_num += 1
